<script>
	import {
		getStorage,
		removeStorage
	} from '@/util/auth.js';
	import {
		isLogin
	} from '@/util/user.js'
	export default {
		onLaunch: function() {},
		onLaunch() {
			uni.loadFontFace({
				source: 'url("https://guoyuan-1306862033.cos.ap-chengdu.myqcloud.com/%E6%96%B9%E6%AD%A3%E6%B1%89%E7%9C%9F%E5%B9%BF%E6%A0%87%E7%AE%80%E4%BD%93.TTF")',
				family: 'FangZhengHanZhenGuangBiaoJianTi',
				global: true,
				success(e) {
					console.log(e)
				},
				fail(e) {
					console.log(e)
				}
			})
			let _this = this;
			uni.addInterceptor('navigateTo', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('redirectTo', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('reLaunch', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('switchTab', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
		},
		methods: {
			watchRouter(e) {
				let url = e.url;
				const index = url.indexOf('?');
				url = index == -1 ? url : url.slice(0, index);
				const hasToken = getStorage('token');
				const whiteList = ['/pages/index/index', '/pages/mine/mine', '/page_other/activity/activity',
					'/page_other/activity/detail', '/page_other/learn/learn', '/page_other/learn/details',
					'/page_other/shopping/shopping', '/page_other/shopping/detail',
					'/page_other/select_area/select_area'
				];
				if (hasToken) {
					return true
				} else {
					if (whiteList.includes(url)) {
						return true
					} else {
						uni.showModal({
							title: '提示',
							content: '需要先登录！',
							cancelText: '先逛逛',
							confirmText: '去登录',
							success(res) {
								if (res.confirm) {
									uni.switchTab({
										url: '/pages/mine/mine'
									})
								} else {
									uni.navigateBack();
								}
							}
						})
					}
				}
				return false;
			}
		}
	}
</script>

<style lang="scss">
	@import url("@/static/icon/iconfont.css");

	view,
	text,
	navigator,
	input,
	picker,
	button,
	image {
		box-sizing: border-box;
	}

	.FangZhengHanZhenGuangBiaoJianTi {
		font-family: 'FangZhengHanZhenGuangBiaoJianTi';
	}

	page {
		min-height: calc(100vh - var(--window-bottom) - var(--window-top));
		background: rgb(248, 248, 248);
	}

	.content {
		width: 100%;
	}
</style>